﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace MyAlbum.Services
{
    public class WebUser : IUser
    {
       
        System.Security.Principal.IPrincipal _user;
        public WebUser()
        {
            if (HttpContext.Current == null ||
                HttpContext.Current.User == null)
            {
                throw new InvalidOperationException("No user is in context");
            }
            this._user = HttpContext.Current.User;

        }
        public WebUser(System.Security.Principal.IPrincipal user)
        {
            this._user = user;
        }
        public bool IsInRole(string role)
        {
            return this._user.IsInRole(role);
        }

        public string Name
        {
            get { return this._user.Identity.Name; }
            set { throw new InvalidOperationException(); }
        }


        public string Email{get;set;}

        public string Password{get;set;}

        public List<string> Roles { get; set; }

        public override string ToString()
        {
            return this.Name;
        }
    }
}
